package com.hxm.meizi.provider;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hxm.meizi.R;
import com.hxm.meizi.entity.ZhuanTi;

import me.drakeet.multitype.ItemViewProvider;

/**
 * Created by hxm on 2017/2/19.
 */

public class ZhuanTiProvider extends ItemViewProvider<ZhuanTi, ZhuanTiProvider.ZhuanTiHolder> {
    private OnZhuanTiClickListener listener;

    public ZhuanTiProvider(OnZhuanTiClickListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ZhuanTiHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.item_zhuan_ti_provider, parent, false);
        return new ZhuanTiHolder(view);
    }

    @Override
    protected void onBindViewHolder(@NonNull final ZhuanTiHolder holder, @NonNull final ZhuanTi zhuanTi) {
        holder.tvName.setText(zhuanTi.getName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null) {
                    listener.onClick(zhuanTi.getUrl());
                }
            }
        });
    }

    public interface OnZhuanTiClickListener {
        void onClick(String url);
    }

    static class ZhuanTiHolder extends RecyclerView.ViewHolder {
        private TextView tvName;

        public ZhuanTiHolder(View itemView) {
            super(itemView);
            tvName = (TextView) itemView.findViewById(R.id.tv_name);
        }
    }

}
